package com.woniuxy.dead;

import com.rabbitmq.client.*;
import com.woniuxy.utils.Utils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class DeadConsume {
    //声明死信交换机 死信队列 死信消费者
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = Utils.getConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare("deadExchange", BuiltinExchangeType.DIRECT);
        channel.queueDeclare("deadQueue",false,false,false,null);
        channel.queueBind("deadQueue","deadExchange","dead1");
        channel.basicConsume("deadQueue",false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("DeadConsume 接受消息 "+new String(body));
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        });
    }
}
